﻿using System.Data.SqlClient;

namespace zijian666.Data;
internal static class TestExtensions
{
    public static SqlCommand SqlCommand(this FormattableSql? sql)
    {
        ArgumentNullException.ThrowIfNull(sql);
        if (!DbProviderFactories.TryGetFactory("System.Data.SqlClient", out _))
        {
            DbProviderFactories.RegisterFactory("System.Data.SqlClient", SqlClientFactory.Instance);
        }
        var conn = new SqlConnection();
        return (SqlCommand)conn.CreateCommand(sql);
    }

    public static string SqlCommandText(this FormattableSql? sql)
    {
        return sql.SqlCommand().CommandText;
    }
}
